<template>
  <!-- 放置全屏图标 -->
  <div>
    <!-- svg-icon组件, 配置icon-class属性, 配置成svg的文件名即可 -->
    <svg-icon
      v-if="!isFullScreen"
      icon-class="fullscreen"
      class="fullscreen"
      @click="toggleFullScreen"
    />

    <svg-icon
      v-else
      icon-class="fullscreen"
      class="fullscreen"
      @click="toggleFullScreen"
    />
  </div>
</template>

<script>
// 底层:
// 1 开启全屏: document.documentElement.requestFullscreen()
// 2 关闭全屏: document.exitFullscreen()

// 属性: ScreenFull.isEnabled 获取浏览器是否支持全屏, 支持, 就返回 true
// 方法: ScreenFull.toggle(element)  切换全屏状态
import ScreenFull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      isFullScreen: false // 默认不全屏
    }
  },
  methods: {
    toggleFullScreen() {
      console.log('全屏')
      // 查看是否支持全屏
      if (ScreenFull.isEnabled) {
        // 支持
        ScreenFull.toggle()
        this.isFullScreen = !this.isFullScreen
      } else {
        this.$message.error('你的浏览器版本多地不支持全屏功能哦')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
 .fullscreen {
  width: 20px;
  height: 20px;
  fill: #fff;
  cursor: pointer;
 }
</style>
